package cn.itcast.web.controller.stat;

import cn.itcast.service.stat.StatService;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/stat")
public class StatController extends BaseController {

    @Reference(check = false, retries = 0)
    private StatService statService;

    /*
        作用：进入对应的报表页面
        url:  /stat/toCharts.do?chartsType=factory
        参数：对应报表页面类型
        返回值： 对应的报表页面
     */
    @RequestMapping("/toCharts.do")
    public String toCharts(String chartsType) {

        return "stat/stat-" + chartsType;
    }


    /*
     作用：提供厂家的销售额数据
     url:  /stat/getFactoryData.do
     参数：无
     返回值： 厂家的销售额json数据
  */
    @RequestMapping("/getFactoryData.do")
    @ResponseBody
    public List<Map<String, Object>> getFactoryData(String chartsType) {
        List<Map<String, Object>> list = statService.getFactoryData(getLoginCompanyId());
        return list;
    }

    /*
    作用：统计产品的销售额
    url: /stat/getSellData.do
    参数：无
    返回数据： 统计产品的销售额
 */
    @RequestMapping("/getSellData")
    @ResponseBody
    public List<Map<String, Object>> getSellData() {
        return statService.getSellData(getLoginCompanyId());
    }


    /*
      作用：统计厂家地方区域的数量
      url: /stat/getFactoryAddressData.do
      参数：无
      返回数据： 统计每小时访问人数


   */
    @RequestMapping("/getFactoryAddressData")
    @ResponseBody
    public List<Map<String, Object>> getFactoryAddressData() {
        List<Map<String, Object>> list = statService.getFactoryAddressData();
        System.out.println("-------------------");
     /*  List<Map<String, Object>>  list= new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        map.put("name","长沙");
        map.put("value",19);
        list.add(map);
        HashMap<String, Object> map1 = new HashMap<>();
        map1.put("name","武汉");
        map1.put("value",20);
        list.add(map1);*/
        return list;

    }
    //跳转试验
    @RequestMapping("/toABC")
    public String toABC() {
        /*List<Map<String, Object>> list = statService.getFactoryAddressData();
        System.out.println("-------------------");*/
        List<Map<String, Object>>  list= new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        map.put("name","长沙");
        map.put("value",19);
        list.add(map);
        HashMap<String, Object> map1 = new HashMap<>();
        map1.put("name","武汉");
        map1.put("value",20);
        list.add(map1);
        response.setContentType("text/html;charset=utf-8");
        return "redirect:/abc.jsp";
    }


    /*
     作用：统计每小时访问人数
     url: /stat/getOnlineData.do
     参数：无
     返回数据： 统计每小时访问人数
  */
    @RequestMapping("/getOnLineData")
    @ResponseBody
    public List<Map<String, Object>> getOnLineData() {
        return statService.getOnLineData();
    }
}
